﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace QuanLySuKien
{
    public partial class XemDiaDiem : System.Web.UI.Page
    {
        string strCon = "Data Source=192.168.1.100;Initial Catalog=quanlysukien;User ID=sa;Password=123456";
        DataTable table = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        void LoadData()
        {
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter("Select * from DiaDiem", strCon);
                adapter.Fill(table);
                GridView1.DataSource = table;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                StatusLabel.Text = ex.Message;
            }
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            string KV = DropDownList1.SelectedValue;
            DataTable table1 = new DataTable();
            
            //string query = @"SELECT TenDiaDiem, DiaDiem.MaKV, DiaDiem.DiaChi, LienHe, SucChua, Gia, DiaDiem.Mota, DiaDiem.TrangThai FROM DiaDiem, KhuVuc WHERE DiaDiem.MaKV=KhuVuc.MaKV and KhuVuc.TenKhuVuc = '" + KV + "'";
            string query = "SELECT * FROM DiaDiem WHERE MaKV = '"+KV+"'";
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter(query, strCon);
                adapter.Fill(table1);
                GridView2.DataSource = table1;
                GridView2.DataBind();
            }
            catch (Exception ex)
            {
                StatusLabel.Text = ex.Message;
            }  
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = table;
            GridView1.DataBind();
        }
    }
}